package com.alpha.feign.common;

import com.alpha.core.http.Response;
import com.alpha.feign.common.entity.Resource;
import com.alpha.feign.common.entity.User;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 用户接口
 *
 * @author chenruwan
 * @since 2022-01-01
 */
@FeignClient(value = "alpha-common", contextId = "users")
public interface UserFeignClient {

    /**
     * 获取用户所有资源
     *
     * @param userId 用户标识
     * @return 资源列表
     */
    @GetMapping("/users/resources")
    Response<List<Resource>> getResources(@RequestParam("userId") String userId);

    /**
     * 根据用户名和密码查询用户
     *
     * @param username 用户名
     * @param password 密码
     * @return 用户
     */
    @GetMapping("/users")
    Response<Page<User>> query(@RequestParam("username") String username, @RequestParam("password") String password);

    /**
     * 获取用户详情
     *
     * @param id 用户Id
     * @return 用户信息
     */
    @GetMapping("/users/{id}")
    Response<User> get(@PathVariable("id") Long id);

    /**
     * 新增用户
     *
     * @param user 用户信息
     * @return Response
     */
    @PostMapping("/users")
    Response<Long> save(@Validated @RequestBody User user);
}
